<?php
namespace app\api\logic;
use think\Db;
use services\OpensslService;
class Base{
    public $return_data=['Code'=>1,'Msg'=>'','ErrorSql'=>'','Data'=>[]];

    public function __construct()
    {
    }
    /****创建令牌*****/
    public function createUserToken($data){
        if(!is_array($data)) return false;
        $map=array();
        $expiresAt = $data["created_at"] + $data['expires_in'];
        $map["user_id"]=trim($data["uid"]);//自己编号或上级编号
        $map["created_at"]=$data["created_at"];
        $map["expires_at"]=$expiresAt;
        $map["ip"] = ip2long($data["ip"]);
        $OpensslService = new OpensslService();
        $token=$OpensslService->aes_encrypt(json_encode($map));
        return $token;
    }
    /****解析令牌*****/
    public function analysisUserToken($data){
    }

    /**生成编号**/
    public function generat_add($save){
        if(!is_array($save)) return False;
        try{
            Db::startTrans();
            $res = Db::name('generat_no')->insertGetId($save);
            Db::commit();
        }catch (Exception $e) {
            Db::rollback();
            return False;
        }
        return $res;
    }

    public function printResult($return_data){
        if(!is_array($return_data)){
            $return_data['Code']=0;
            $return_data['Msg']='输出信息不符合规范';
        }
        return $return_data;
    }

}
